package com.example.utils;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

public class HamcrestUtils {
    
    /**
     * 断言相等封装
     */
    public void assertEquals(Object actual, Object expected) {
        assertThat(actual, equalTo(expected));
    }

    /**
     * 匹配字符串以 XX 开头
     *
     * @param actual
     * @param expected
     * @return void
     * @date 2023/9/25 19:22
     * @version 1.0
     */
    public void assertStartWith(String actual, String expected) {
        assertThat(actual, startsWith(expected));
    }

    /**
     * 匹配是否包含指定字符串
     *
     * @param actual
     * @param expected
     * @return void
     * @date 2023/9/25 19:25
     * @version 1.0
     */
    public void assertContainsString(String actual, String expected) {
        assertThat(actual, containsString(expected));
    }

    /**
     * 匹配所有指定的匹配项，可指定多个匹配条件
     *
     * @param result
     * @param start
     * @param contains
     * @return void
     * @author Gaoqd
     * @date 2023/10/8 10:06
     * @version 1.0
     */
    public void assertAllOf(String result, String start, String contains) {
        assertThat(result, allOf(startsWith(start), containsString(contains)));
    }

    /**
     * 实际结果与预期结果都匹配
     * @param result 
     * @param actual 
     * @param expected 
     * @return void
     * @author Gaoqd
     * @date 2023/10/10 08:58
     * @version 1.0       
     */
    public void assertBoth(String result, String actual, String expected) {
        assertThat(result, both(containsString(actual)).and(containsString(expected)));
    }
}